

package com.lry.rpc.starter.util;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.util.Assert;

public abstract class WrapperUtils {
    public WrapperUtils() {
    }

    public static ConfigurableListableBeanFactory unwrap(BeanFactory beanFactory) throws IllegalArgumentException {
        Assert.isInstanceOf(ConfigurableListableBeanFactory.class, beanFactory, "The 'beanFactory' argument is not an instance of ConfigurableListableBeanFactory, is it running in Spring container?");
        return (ConfigurableListableBeanFactory)ConfigurableListableBeanFactory.class.cast(beanFactory);
    }

    public static ConfigurableEnvironment unwrap(Environment environment) throws IllegalArgumentException {
        Assert.isInstanceOf(ConfigurableEnvironment.class, environment, "The 'environment' argument is not a instance of ConfigurableEnvironment, is it running in Spring container?");
        return (ConfigurableEnvironment)environment;
    }
}
